package array

func rob(nums []int) int {

	dp := make([]int, len(nums)+1)
	dp[0] = 0
	dp[1] = nums[0]

	max := func(i, j int) int {
		if i > j {
			return i
		}
		return j
	}

	for i := 2; i < len(dp); i++ {
		dp[i] = max(dp[i-1], dp[i-2]+nums[i-1])
	}
	return dp[len(dp)-1]
}
